#include <iostream>
#define MAXMN 105
using namespace std;

char field[MAXMN][MAXMN];
int dxdy[8][2] = {
    {-1, -1}, {-1, 0}, {1, 0},
    {0, -1}, {0, 1},
    {1, -1}, {1, 0}, {1, 1}
};

int N, M, sum;

void solve();

int main() {
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= M; j++)
            cin >> field[i][j];
    solve();
    return 0;
}

void dfs(int x, int y) {
    field[x][y] = '.';
    for (int i = 0; i < 8; i++) {
        int nx = x + dxdy[i][0],
            ny = y + dxdy[i][1];
        if (field[nx][ny] == 'W')
            dfs(nx, ny);
    }
}

void solve() {
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (field[i][j] == 'W') {
                sum++;
                dfs(i, j);
            }
        }
    } 
    cout << sum << endl;
}


